package basics;

import java.util.HashMap;

public class test {

    public void test1(){
        synchronized (this)
        {
            int i = 4;
            while (i-->0){
                System.out.println(Thread.currentThread().getName() + ":" + i);
                try {
                    Thread.sleep(500);
                }catch (Exception ie){

                }
            }
        }
    }

    public synchronized void test2 (){
        int i = 4;
        while (i --> 0){
            System.out.println(Thread.currentThread().getName() + ":" + i);
            try{
                Thread.sleep(500);
            }catch (InterruptedException ie){

            }
        }
    }



    public static void main(String[] args) {
        test t = new test();
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                t.test1();
            }
        },"test1");
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                t.test2();
            }
        },"test2");
        thread1.start();
        thread2.start();

    }

}
